/*
 * @Author: c
 * @Date: 2024-01-08 22:21:09
 * @LastEditTime: 2024-02-27 16:25:29
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\video\video.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, ParseIntPipe, ParseUUIDPipe, Post, Put, Query, Req } from '@nestjs/common';
import { Request } from 'express';
import { SkipAuth } from 'src/core/system/auth/constants';
import { VideoForm } from './dto/create-video.dto';
import { VideoPageQuery } from './dto/search-video.dto';
import { VideoService } from './video.service';

/**
 * 精选视频
 */
@Controller('video')
export class VideoController {
  constructor(private readonly videoService: VideoService) { }

  /**
    * 歌曲-分页查询
    * @param pageDto 
    * @returns 
    */
  @SkipAuth()
  @Get("page")
  getPage(@Req() req, @Query() pageDto: VideoPageQuery) {
    return this.videoService.page(req.user, pageDto);
  }

  /**
   * 歌曲-下拉选项
   * @param videoName 歌曲名称 
   * @returns 
   */
  @Get("options")
  async listVideoOptions(@Query() { name, artistIds }: VideoPageQuery) {
    const videoOptions = await this.videoService.listVideoOptions(name, artistIds)
    return videoOptions
  }

  /**
   * 歌曲-新增
   * @param pageDto 
   * @returns 
   */
  @Post()
  saveVideo(@Req() req: Request, @Body() videoForm: VideoForm) {

    return this.videoService.saveVideo(req, videoForm); //必须return 不然报错终止整个运行的进程
  }


  /**
  * 歌曲-单条表单数据
  * @param typeCode 
  * @returns 
  */
  @SkipAuth()
  @Get(":id/form")
  getVideoFormData(@Req() req: any,
    @Param('id', ParseUUIDPipe) id
  ) {
    return this.videoService.getVideoFormData(req.user, id);
  }

  // /**
  // * 歌曲-播放视频
  // * @param typeCode 
  // * @returns 
  // */
  // @Get("tracklink")
  // getTracklink(@Req() req: Request,
  //   @Query() trackLink: TrackLinkQueryDto
  // ) {
  //   return this.videoService.getTrackLink(req, trackLink);
  // }


  /**
   * 歌曲-修改
   * @param videoForm 
   * @returns 
   */
  @Put(':videoId')
  async updateVideo(@Param('videoId', ParseIntPipe) videoId: number, @Body() videoForm: VideoForm) {

    return await this.videoService.update(videoId, videoForm); //必须return 不然报错终止整个运行的进程
  }

  /**
   * 歌曲-删除
   * @param id
   * @returns 
   */
  @Delete(':ids')
  remove(@Param('ids', ParseArrayPipe) ids: number[]) {
    return this.videoService.removeByIds(ids);
  }
}
